import errno

from langchain_chroma import Chroma

from promptAdmin.prompt_app.vector_databases.base import VectorBase

chroma_vectorstore_instance = ""
class ChromaDatabase(VectorBase):

    def save_chunks_into_vectorstore(self, content_chunks, embedding_model):
        # 参考官网链接：https://python.langchain.com/docs/modules/data_connection/vectorstores/
        # ① FAISS
        # pip install faiss-gpu (如果没有GPU，那么 pip install faiss-cpu)
        vectorstore = Chroma.from_texts(content_chunks, embedding_model)

        global chroma_vectorstore_instance
        chroma_vectorstore_instance = vectorstore
        return vectorstore

    def get_vectorstore(self, embedding_model):
        if(chroma_vectorstore_instance == ""):
            raise Exception('没有实例化数据库')
        vectorstore = chroma_vectorstore_instance
        return vectorstore
